Hello, Quarto

library(ggplot2)
library(plotly)

Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':

    last_plot
The following object is masked from 'package:stats':

    filter
The following object is masked from 'package:graphics':

    layout
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ lubridate 1.9.3     ✔ tibble    3.2.1
✔ purrr     1.0.2     ✔ tidyr     1.3.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks plotly::filter(), stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
df <- read.csv('data/processed-data/gender_inequality_and_economic_indicators_dataset_clean_final.csv')

dim(df)
[1] 190  63
str(df)
'data.frame':   190 obs. of  63 variables:
 $ Economy                                                                               : chr  "afghanistan" "albania" "algeria" "angola" ...
 $ Economy.Code                                                                          : chr  "AFG" "ALB" "DZA" "AGO" ...
 $ ISO.Code                                                                              : chr  "AFG" "ALB" "DZA" "AGO" ...
 $ Region                                                                                : chr  "South Asia" "Europe & Central Asia" "Middle East & North Africa" "Sub-Saharan Africa" ...
 $ Income.Group                                                                          : chr  "Low income" "Upper middle income" "Lower middle income" "Lower middle income" ...
 $ Report.Year                                                                           : int  2018 2018 2018 2018 2018 2018 2018 2018 2018 2018 ...
 $ WBL.INDEX                                                                             : num  38.1 91.3 57.5 73.1 66.3 73.1 82.5 96.9 94.4 78.8 ...
 $ MOBILITY                                                                              : int  50 100 75 100 75 100 100 100 100 100 ...
 $ Can.a.woman.choose.where.to.live.in.the.same.way.as.a.man.                            : chr  "No" "Yes" "Yes" "Yes" ...
 $ Can.a.woman.travel.outside.her.home.in.the.same.way.as.a.man.                         : chr  "No" "Yes" "Yes" "Yes" ...
 $ Can.a.woman.apply.for.a.passport.in.the.same.way.as.a.man.                            : chr  "Yes" "Yes" "No" "Yes" ...
 $ Can.a.woman.travel.outside.the.country.in.the.same.way.as.a.man.                      : chr  "Yes" "Yes" "Yes" "Yes" ...
 $ WORKPLACE                                                                             : int  75 100 75 50 50 75 50 100 100 100 ...
 $ Can.a.woman.get.a.job.in.the.same.way.as.a.man.                                       : chr  "Yes" "Yes" "Yes" "Yes" ...
 $ Does.the.law.prohibit.discrimination.in.employment.based.on.gender.                   : chr  "No" "Yes" "No" "Yes" ...
 $ Is.there.legislation.on.sexual.harassment.in.employment.                              : chr  "Yes" "Yes" "Yes" "No" ...
 $ Are.there.criminal.penalties.or.civil.remedies.for.sexual.harassment.in.employment.   : chr  "Yes" "Yes" "Yes" "No" ...
 $ PAY                                                                                   : int  0 100 50 50 75 50 75 100 100 0 ...
 $ Does.the.law.mandate.equal.remuneration.for.work.of.equal.value.                      : chr  "No" "Yes" "Yes" "Yes" ...
 $ Can.a.woman.work.at.night.in.the.same.way.as.a.man.                                   : chr  "No" "Yes" "No" "Yes" ...
 $ Can.a.woman.work.in.a.job.deemed.dangerous.in.the.same.way.as.a.man.                  : chr  "No" "Yes" "No" "No" ...
 $ Can.a.woman.work.in.an.industrial.job.in.the.same.way.as.a.man.                       : chr  "No" "Yes" "Yes" "No" ...
 $ MARRIAGE                                                                              : int  20 100 60 100 100 100 80 100 100 100 ...
 $ Is.the.law.free.of.legal.provisions.that.require.a.married.woman.to.obey.her.husband. : chr  "No" "Yes" "Yes" "Yes" ...
 $ Can.a.woman.be.head.of.household.in.the.same.way.as.a.man.                            : chr  "Yes" "Yes" "Yes" "Yes" ...
 $ Is.there.legislation.specifically.addressing.domestic.violence.                       : chr  "No" "Yes" "Yes" "Yes" ...
 $ Can.a.woman.obtain.a.judgment.of.divorce.in.the.same.way.as.a.man.                    : chr  "No" "Yes" "No" "Yes" ...
 $ Does.a.woman.have.the.same.rights.to.remarry.as.a.man.                                : chr  "No" "Yes" "No" "Yes" ...
 $ PARENTHOOD                                                                            : int  20 80 60 60 0 60 80 100 80 80 ...
 $ Is.paid.leave.of.at.least.14.weeks.available.to.mothers.                              : chr  "No" "Yes" "Yes" "No" ...
 $ Length.of.paid.maternity.leave                                                        : int  90 365 98 90 91 90 140 0 112 126 ...
 $ Does.the.government.administer.100.percent.of.maternity.leave.benefits.               : chr  "No" "Yes" "Yes" "Yes" ...
 $ Is.there.paid.leave.available.to.fathers.                                             : chr  "Yes" "Yes" "Yes" "Yes" ...
 $ Length.of.paid.paternity.leave                                                        : int  14 3 3 1 0 2 0 14 0 0 ...
 $ Is.there.paid.parental.leave.                                                         : chr  "No" "No" "No" "No" ...
 $ Shared.days                                                                           : int  0 0 0 0 0 0 660 126 540 1039 ...
 $ Days.for.the.mother                                                                   : int  0 0 0 0 0 0 0 0 0 0 ...
 $ Days.for.the.father                                                                   : int  0 0 0 0 0 0 0 0 0 0 ...
 $ Is.dismissal.of.pregnant.workers.prohibited.                                          : chr  "No" "Yes" "No" "Yes" ...
 $ ENTREPRENEURSHIP                                                                      : int  75 100 75 100 75 75 75 100 100 100 ...
 $ Does.the.law.prohibit.discrimination.in.access.to.credit.based.on.gender.             : chr  "No" "Yes" "No" "Yes" ...
 $ Can.a.woman.sign.a.contract.in.the.same.way.as.a.man.                                 : chr  "Yes" "Yes" "Yes" "Yes" ...
 $ Can.a.woman.register.a.business.in.the.same.way.as.a.man.                             : chr  "Yes" "Yes" "Yes" "Yes" ...
 $ Can.a.woman.open.a.bank.account.in.the.same.way.as.a.man.                             : chr  "Yes" "Yes" "Yes" "Yes" ...
 $ ASSETS                                                                                : int  40 100 40 100 80 100 100 100 100 100 ...
 $ Do.women.and.men.have.equal.ownership.rights.to.immovable.property.                   : chr  "Yes" "Yes" "Yes" "Yes" ...
 $ Do.sons.and.daughters.have.equal.rights.to.inherit.assets.from.their.parents.         : chr  "No" "Yes" "No" "Yes" ...
 $ Do.male.and.female.surviving.spouses.have.equal.rights.to.inherit.assets.             : chr  "No" "Yes" "No" "Yes" ...
 $ Does.the.law.grant.spouses.equal.administrative.authority.over.assets.during.marriage.: chr  "Yes" "Yes" "Yes" "Yes" ...
 $ Does.the.law.provide.for.the.valuation.of.nonmonetary.contributions.                  : chr  "No" "Yes" "No" "Yes" ...
 $ PENSION                                                                               : int  25 50 25 25 75 25 100 75 75 50 ...
 $ Is.the.age.at.which.women.and.men.can.retire.with.full.pension.benefits.the.same.     : chr  "No" "No" "No" "No" ...
 $ Is.the.age.at.which.women.and.men.can.retire.with.partial.pension.benefits.the.same.  : chr  "No" "No" "No" "Yes" ...
 $ Is.the.mandatory.retirement.age.for.women.and.men.the.same.                           : chr  "Yes" "Yes" "No" "No" ...
 $ Are.periods.of.absence.due.to.childcare.accounted.for.in.pension.benefits.            : chr  "No" "Yes" "Yes" "No" ...
 $ match                                                                                 : logi  TRUE TRUE TRUE TRUE TRUE TRUE ...
 $ X                                                                                     : int  2 5 60 4 12 9 10 13 14 15 ...
 $ Country.Code                                                                          : chr  "AFG" "ALB" "DZA" "AGO" ...
 $ Foreign_direct_investment                                                             : num  0.66 7.95 0.75 -8.13 12.18 ...
 $ agriculture_forestry_value_added                                                      : num  -4.42 1.18 3.26 -2.48 1.02 ...
 $ GNI.per.capita                                                                        : int  520 4860 4510 1970 17330 12430 4410 53150 48980 4080 ...
 $ net_barter_terms_of_trade_index                                                       : num  106 104 111 137 94 ...
 $ gdp_per_person_employed                                                               : num  12983 34407 60730 25229 99993 ...
summary(df)
   Economy          Economy.Code         ISO.Code            Region         
 Length:190         Length:190         Length:190         Length:190        
 Class :character   Class :character   Class :character   Class :character  
 Mode  :character   Mode  :character   Mode  :character   Mode  :character  
                                                                            
                                                                            
                                                                            
                                                                            
 Income.Group        Report.Year     WBL.INDEX         MOBILITY     
 Length:190         Min.   :2018   Min.   : 26.90   Min.   :  0.00  
 Class :character   1st Qu.:2018   1st Qu.: 62.65   1st Qu.: 75.00  
 Mode  :character   Median :2018   Median : 77.50   Median :100.00  
                    Mean   :2018   Mean   : 73.71   Mean   : 86.18  
                    3rd Qu.:2018   3rd Qu.: 86.90   3rd Qu.:100.00  
                    Max.   :2018   Max.   :100.00   Max.   :100.00  
                                                                    
 Can.a.woman.choose.where.to.live.in.the.same.way.as.a.man.
 Length:190                                                
 Class :character                                          
 Mode  :character                                          
                                                           
                                                           
                                                           
                                                           
 Can.a.woman.travel.outside.her.home.in.the.same.way.as.a.man.
 Length:190                                                   
 Class :character                                             
 Mode  :character                                             
                                                              
                                                              
                                                              
                                                              
 Can.a.woman.apply.for.a.passport.in.the.same.way.as.a.man.
 Length:190                                                
 Class :character                                          
 Mode  :character                                          
                                                           
                                                           
                                                           
                                                           
 Can.a.woman.travel.outside.the.country.in.the.same.way.as.a.man.
 Length:190                                                      
 Class :character                                                
 Mode  :character                                                
                                                                 
                                                                 
                                                                 
                                                                 
   WORKPLACE      Can.a.woman.get.a.job.in.the.same.way.as.a.man.
 Min.   :  0.00   Length:190                                     
 1st Qu.: 50.00   Class :character                               
 Median :100.00   Mode  :character                               
 Mean   : 75.66                                                  
 3rd Qu.:100.00                                                  
 Max.   :100.00                                                  
                                                                 
 Does.the.law.prohibit.discrimination.in.employment.based.on.gender.
 Length:190                                                         
 Class :character                                                   
 Mode  :character                                                   
                                                                    
                                                                    
                                                                    
                                                                    
 Is.there.legislation.on.sexual.harassment.in.employment.
 Length:190                                              
 Class :character                                        
 Mode  :character                                        
                                                         
                                                         
                                                         
                                                         
 Are.there.criminal.penalties.or.civil.remedies.for.sexual.harassment.in.employment.
 Length:190                                                                         
 Class :character                                                                   
 Mode  :character                                                                   
                                                                                    
                                                                                    
                                                                                    
                                                                                    
      PAY        
 Min.   :  0.00  
 1st Qu.: 50.00  
 Median : 75.00  
 Mean   : 63.29  
 3rd Qu.:100.00  
 Max.   :100.00  
                 
 Does.the.law.mandate.equal.remuneration.for.work.of.equal.value.
 Length:190                                                      
 Class :character                                                
 Mode  :character                                                
                                                                 
                                                                 
                                                                 
                                                                 
 Can.a.woman.work.at.night.in.the.same.way.as.a.man.
 Length:190                                         
 Class :character                                   
 Mode  :character                                   
                                                    
                                                    
                                                    
                                                    
 Can.a.woman.work.in.a.job.deemed.dangerous.in.the.same.way.as.a.man.
 Length:190                                                          
 Class :character                                                    
 Mode  :character                                                    
                                                                     
                                                                     
                                                                     
                                                                     
 Can.a.woman.work.in.an.industrial.job.in.the.same.way.as.a.man.
 Length:190                                                     
 Class :character                                               
 Mode  :character                                               
                                                                
                                                                
                                                                
                                                                
    MARRIAGE     
 Min.   :  0.00  
 1st Qu.: 60.00  
 Median : 80.00  
 Mean   : 77.16  
 3rd Qu.:100.00  
 Max.   :100.00  
                 
 Is.the.law.free.of.legal.provisions.that.require.a.married.woman.to.obey.her.husband.
 Length:190                                                                           
 Class :character                                                                     
 Mode  :character                                                                     
                                                                                      
                                                                                      
                                                                                      
                                                                                      
 Can.a.woman.be.head.of.household.in.the.same.way.as.a.man.
 Length:190                                                
 Class :character                                          
 Mode  :character                                          
                                                           
                                                           
                                                           
                                                           
 Is.there.legislation.specifically.addressing.domestic.violence.
 Length:190                                                     
 Class :character                                               
 Mode  :character                                               
                                                                
                                                                
                                                                
                                                                
 Can.a.woman.obtain.a.judgment.of.divorce.in.the.same.way.as.a.man.
 Length:190                                                        
 Class :character                                                  
 Mode  :character                                                  
                                                                   
                                                                   
                                                                   
                                                                   
 Does.a.woman.have.the.same.rights.to.remarry.as.a.man.   PARENTHOOD    
 Length:190                                             Min.   :  0.00  
 Class :character                                       1st Qu.: 20.00  
 Mode  :character                                       Median : 60.00  
                                                        Mean   : 51.58  
                                                        3rd Qu.: 80.00  
                                                        Max.   :100.00  
                                                                        
 Is.paid.leave.of.at.least.14.weeks.available.to.mothers.
 Length:190                                              
 Class :character                                        
 Mode  :character                                        
                                                         
                                                         
                                                         
                                                         
 Length.of.paid.maternity.leave
 Min.   :  0.0                 
 1st Qu.: 84.0                 
 Median : 98.0                 
 Mean   :101.9                 
 3rd Qu.:112.0                 
 Max.   :635.0                 
                               
 Does.the.government.administer.100.percent.of.maternity.leave.benefits.
 Length:190                                                             
 Class :character                                                       
 Mode  :character                                                       
                                                                        
                                                                        
                                                                        
                                                                        
 Is.there.paid.leave.available.to.fathers. Length.of.paid.paternity.leave
 Length:190                                Min.   : 0.000                
 Class :character                          1st Qu.: 0.000                
 Mode  :character                          Median : 0.500                
                                           Mean   : 4.584                
                                           3rd Qu.: 4.750                
                                           Max.   :90.000                
                                                                         
 Is.there.paid.parental.leave.  Shared.days      Days.for.the.mother
 Length:190                    Min.   :   0.00   Min.   :  0.00     
 Class :character              1st Qu.:   0.00   1st Qu.:  0.00     
 Mode  :character              Median :   0.00   Median :  0.00     
                               Mean   :  67.85   Mean   : 12.72     
                               3rd Qu.:   0.00   3rd Qu.:  0.00     
                               Max.   :1095.00   Max.   :478.00     
                                                                    
 Days.for.the.father Is.dismissal.of.pregnant.workers.prohibited.
 Min.   :  0.00      Length:190                                  
 1st Qu.:  0.00      Class :character                            
 Median :  0.00      Mode  :character                            
 Mean   : 10.26                                                  
 3rd Qu.:  0.00                                                  
 Max.   :365.00                                                  
                                                                 
 ENTREPRENEURSHIP
 Min.   :  0.00  
 1st Qu.: 75.00  
 Median : 75.00  
 Mean   : 82.89  
 3rd Qu.:100.00  
 Max.   :100.00  
                 
 Does.the.law.prohibit.discrimination.in.access.to.credit.based.on.gender.
 Length:190                                                               
 Class :character                                                         
 Mode  :character                                                         
                                                                          
                                                                          
                                                                          
                                                                          
 Can.a.woman.sign.a.contract.in.the.same.way.as.a.man.
 Length:190                                           
 Class :character                                     
 Mode  :character                                     
                                                      
                                                      
                                                      
                                                      
 Can.a.woman.register.a.business.in.the.same.way.as.a.man.
 Length:190                                               
 Class :character                                         
 Mode  :character                                         
                                                          
                                                          
                                                          
                                                          
 Can.a.woman.open.a.bank.account.in.the.same.way.as.a.man.     ASSETS      
 Length:190                                                Min.   :  0.00  
 Class :character                                          1st Qu.: 60.00  
 Mode  :character                                          Median :100.00  
                                                           Mean   : 80.32  
                                                           3rd Qu.:100.00  
                                                           Max.   :100.00  
                                                                           
 Do.women.and.men.have.equal.ownership.rights.to.immovable.property.
 Length:190                                                         
 Class :character                                                   
 Mode  :character                                                   
                                                                    
                                                                    
                                                                    
                                                                    
 Do.sons.and.daughters.have.equal.rights.to.inherit.assets.from.their.parents.
 Length:190                                                                   
 Class :character                                                             
 Mode  :character                                                             
                                                                              
                                                                              
                                                                              
                                                                              
 Do.male.and.female.surviving.spouses.have.equal.rights.to.inherit.assets.
 Length:190                                                               
 Class :character                                                         
 Mode  :character                                                         
                                                                          
                                                                          
                                                                          
                                                                          
 Does.the.law.grant.spouses.equal.administrative.authority.over.assets.during.marriage.
 Length:190                                                                            
 Class :character                                                                      
 Mode  :character                                                                      
                                                                                       
                                                                                       
                                                                                       
                                                                                       
 Does.the.law.provide.for.the.valuation.of.nonmonetary.contributions.
 Length:190                                                          
 Class :character                                                    
 Mode  :character                                                    
                                                                     
                                                                     
                                                                     
                                                                     
    PENSION     
 Min.   : 25.0  
 1st Qu.: 50.0  
 Median : 75.0  
 Mean   : 72.5  
 3rd Qu.:100.0  
 Max.   :100.0  
                
 Is.the.age.at.which.women.and.men.can.retire.with.full.pension.benefits.the.same.
 Length:190                                                                       
 Class :character                                                                 
 Mode  :character                                                                 
                                                                                  
                                                                                  
                                                                                  
                                                                                  
 Is.the.age.at.which.women.and.men.can.retire.with.partial.pension.benefits.the.same.
 Length:190                                                                          
 Class :character                                                                    
 Mode  :character                                                                    
                                                                                     
                                                                                     
                                                                                     
                                                                                     
 Is.the.mandatory.retirement.age.for.women.and.men.the.same.
 Length:190                                                 
 Class :character                                           
 Mode  :character                                           
                                                            
                                                            
                                                            
                                                            
 Are.periods.of.absence.due.to.childcare.accounted.for.in.pension.benefits.
 Length:190                                                                
 Class :character                                                          
 Mode  :character                                                          
                                                                           
                                                                           
                                                                           
                                                                           
   match               X         Country.Code       Foreign_direct_investment
 Mode :logical   Min.   :  2.0   Length:190         Min.   :-117.370         
 FALSE:1         1st Qu.: 60.0   Class :character   1st Qu.:   1.260         
 TRUE :189       Median :129.0   Mode  :character   Median :   2.680         
                 Mean   :131.5                      Mean   :   2.539         
                 3rd Qu.:200.0                      3rd Qu.:   4.240         
                 Max.   :265.0                      Max.   :  29.210         
                 NA's   :1                          NA's   :1                
 agriculture_forestry_value_added GNI.per.capita 
 Min.   :-65.960                  Min.   :  240  
 1st Qu.: -1.230                  1st Qu.: 1980  
 Median :  2.780                  Median : 5700  
 Mean   :  1.666                  Mean   :13684  
 3rd Qu.:  5.530                  3rd Qu.:17330  
 Max.   : 37.660                  Max.   :82470  
 NA's   :1                        NA's   :1      
 net_barter_terms_of_trade_index gdp_per_person_employed
 Min.   : 53.54                  Min.   :  2169         
 1st Qu.: 97.39                  1st Qu.: 16974         
 Median :101.00                  Median : 39836         
 Mean   :103.13                  Mean   : 53378         
 3rd Qu.:106.95                  3rd Qu.: 79411         
 Max.   :136.92                  Max.   :280172         
                                 NA's   :1              
# look up table for region abbreviations
region_labels <- c(
    "East Asia & Pacific" = "EAP",
    "Europe & Central Asia" = "ECA",
    "High income: OECD" = "HIC",
    "Latin America & Caribbean" = "LAC",
    "Middle East & North Africa" = "MENA",
    "South Asia" = "SA",
    "Sub-Saharan Africa" = "SSA"
)
# summary stats for gdp data
gdp_summary <- df %>%
    group_by(Region) %>%
    summarise(
        Mean_GDP_Score = mean(gdp_per_person_employed, na.rm = TRUE),
        Median_GDP_Score = median(gdp_per_person_employed, na.rm = TRUE),
        SD_GDP_Score = sd(gdp_per_person_employed, na.rm = TRUE)
    )

gdp_summary
# A tibble: 7 × 4
  Region                     Mean_GDP_Score Median_GDP_Score SD_GDP_Score
  <chr>                               <dbl>            <dbl>        <dbl>
1 East Asia & Pacific                45222.           23073.       51266.
2 Europe & Central Asia              52027.           51231.       23048.
3 High income: OECD                 114705.          109444.       41572.
4 Latin America & Caribbean          47416.           39721.       27638.
5 Middle East & North Africa         64449.           58770.       35726.
6 South Asia                         25070.           20069.       11615.
7 Sub-Saharan Africa                 18788.           10542.       21457.
# summary stats for gdp data
gni_summary <- df %>%
    group_by(Region) %>%
    summarise(
        Mean_GNI_Score = mean(GNI.per.capita, na.rm = TRUE),
        Median_GNI_Score = median(GNI.per.capita, na.rm = TRUE),
        SD_GNI_Score = sd(GNI.per.capita, na.rm = TRUE)
    )

gni_summary
# A tibble: 7 × 4
  Region                     Mean_GNI_Score Median_GNI_Score SD_GNI_Score
  <chr>                               <dbl>            <dbl>        <dbl>
1 East Asia & Pacific                10543              3850       14924.
2 Europe & Central Asia               8633.             5730        9195.
3 High income: OECD                  41262.            41725       20340.
4 Latin America & Caribbean           9874.             7890        6624.
5 Middle East & North Africa         14144.             4830       16133.
6 South Asia                          3078.             2000        2995.
7 Sub-Saharan Africa                  2244.             1075        3176.
# summary stats for wbl data
wbl_summary <- df %>%
    group_by(Region) %>%
    summarise(
        Mean_wbl_Score = mean(WBL.INDEX, na.rm = TRUE),
        Median_wbl_Score = median(WBL.INDEX, na.rm = TRUE),
        SD_wbl_Score = sd(WBL.INDEX, na.rm = TRUE)
    )

wbl_summary
# A tibble: 7 × 4
  Region                     Mean_wbl_Score Median_wbl_Score SD_wbl_Score
  <chr>                               <dbl>            <dbl>        <dbl>
1 East Asia & Pacific                  70.1             75          12.6 
2 Europe & Central Asia                82.4             82.5         7.96
3 High income: OECD                    94.1             96.9         6.38
4 Latin America & Caribbean            79.0             80.6         9.44
5 Middle East & North Africa           44.0             37.8        16.8 
6 South Asia                           59.2             59.4        13.1 
7 Sub-Saharan Africa                   68.3             70          13.8 
ggplot(df, aes(x = Region)) +
    geom_bar(stat = "count", fill = "skyblue") +
    geom_text(aes(label = ..count..), stat = "count", vjust = -0.5) +
    labs(
        title = "Distribution of Regions within Data",
        x = "Region",
        y = "Count"
    ) +
    theme(plot.title = element_text(hjust = 0.5), axis.text.x = element_text(angle = 45, hjust = 1))
Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
ℹ Please use `after_stat(count)` instead.

# summary stats for mobility data
mobility_summary <- df %>%
    group_by(Region) %>%
    summarise(
        Mean_Mobility_Score = mean(MOBILITY, na.rm = TRUE),
        Median_Mobility_Score = median(MOBILITY, na.rm = TRUE),
        SD_Mobility_Score = sd(MOBILITY, na.rm = TRUE)
    )

mobility_summary
# A tibble: 7 × 4
  Region             Mean_Mobility_Score Median_Mobility_Score SD_Mobility_Score
  <chr>                            <dbl>                 <dbl>             <dbl>
1 East Asia & Pacif…                89                   100               16.3 
2 Europe & Central …                98.9                 100                5.21
3 High income: OECD                100                   100                0   
4 Latin America & C…                90.6                 100               13.8 
5 Middle East & Nor…                46.2                  37.5             39.1 
6 South Asia                        90.6                 100               18.6 
7 Sub-Saharan Africa                81.8                  87.5             22.3 
ggplot(df, aes(x = Region, y = WBL.INDEX)) +
    geom_bar(stat = "identity", fill = "skyblue")  +
    labs(
        title = "Distribution of WBL Score",
        x = "Region",
        y = "WBL"
    ) +
    theme(plot.title = element_text(hjust = 0.5), axis.text.x = element_text(angle = 45, hjust = 1))

## distribution of gdp scores
# histogram
ggplot(df, aes(x = gdp_per_person_employed, fill = Region)) +
    geom_density(alpha = 0.5) +
        theme_minimal() +
    labs(
        title = "Distribution of GDP by Region",
        x = "GDP",
        y = "Frequency"
    ) +
    scale_x_continuous(breaks = seq(0, 10000000, by = 50000)) +
    theme_minimal()
Warning: Removed 1 row containing non-finite outside the scale range
(`stat_density()`).

ggplot(df, aes(x = WBL.INDEX, fill = Region)) +
    geom_histogram(binwidth = 20) +
    theme_minimal() +
    labs(
        title = "Distribution of WBL Scores by Region",
        x = "WBL Score",
        y = "Frequency"
    ) +
    scale_x_continuous(breaks = seq(0, 100, by = 20)) +
    theme_minimal()

threshold_score <- 80
count_under_threshold <- df %>%
    filter(WBL.INDEX < threshold_score) %>%
    group_by(Economy) %>%
    count()
count_under_threshold
# A tibble: 111 × 2
# Groups:   Economy [111]
   Economy                 n
   <chr>               <int>
 1 afghanistan             1
 2 algeria                 1
 3 angola                  1
 4 antigua and barbuda     1
 5 argentina               1
 6 azerbaijan              1
 7 bahrain                 1
 8 bangladesh              1
 9 barbados                1
10 belarus                 1
# ℹ 101 more rows
threshold_score <- 80
count_under_threshold_region <- df %>%
    group_by(Region) %>%
    filter(WBL.INDEX < threshold_score) %>%
    count() 
count_under_threshold_region
# A tibble: 7 × 2
# Groups:   Region [7]
  Region                         n
  <chr>                      <int>
1 East Asia & Pacific           18
2 Europe & Central Asia         10
3 High income: OECD              2
4 Latin America & Caribbean     15
5 Middle East & North Africa    19
6 South Asia                     8
7 Sub-Saharan Africa            39
threshold_score <- 80
count_under_threshold_region <- df %>%
    filter(WBL.INDEX < threshold_score) %>% filter(Region == 'High income: OECD')
count_under_threshold_region
  Economy Economy.Code ISO.Code            Region Income.Group Report.Year
1   chile          CHL      CHL High income: OECD  High income        2018
2   japan          JPN      JPN High income: OECD  High income        2018
  WBL.INDEX MOBILITY Can.a.woman.choose.where.to.live.in.the.same.way.as.a.man.
1      77.5      100                                                        Yes
2      78.8      100                                                        Yes
  Can.a.woman.travel.outside.her.home.in.the.same.way.as.a.man.
1                                                           Yes
2                                                           Yes
  Can.a.woman.apply.for.a.passport.in.the.same.way.as.a.man.
1                                                        Yes
2                                                        Yes
  Can.a.woman.travel.outside.the.country.in.the.same.way.as.a.man. WORKPLACE
1                                                              Yes        75
2                                                              Yes        50
  Can.a.woman.get.a.job.in.the.same.way.as.a.man.
1                                             Yes
2                                             Yes
  Does.the.law.prohibit.discrimination.in.employment.based.on.gender.
1                                                                 Yes
2                                                                 Yes
  Is.there.legislation.on.sexual.harassment.in.employment.
1                                                      Yes
2                                                       No
  Are.there.criminal.penalties.or.civil.remedies.for.sexual.harassment.in.employment.
1                                                                                  No
2                                                                                  No
  PAY Does.the.law.mandate.equal.remuneration.for.work.of.equal.value.
1  75                                                               No
2  25                                                               No
  Can.a.woman.work.at.night.in.the.same.way.as.a.man.
1                                                 Yes
2                                                 Yes
  Can.a.woman.work.in.a.job.deemed.dangerous.in.the.same.way.as.a.man.
1                                                                  Yes
2                                                                   No
  Can.a.woman.work.in.an.industrial.job.in.the.same.way.as.a.man. MARRIAGE
1                                                             Yes       60
2                                                              No       80
  Is.the.law.free.of.legal.provisions.that.require.a.married.woman.to.obey.her.husband.
1                                                                                   Yes
2                                                                                   Yes
  Can.a.woman.be.head.of.household.in.the.same.way.as.a.man.
1                                                         No
2                                                        Yes
  Is.there.legislation.specifically.addressing.domestic.violence.
1                                                             Yes
2                                                             Yes
  Can.a.woman.obtain.a.judgment.of.divorce.in.the.same.way.as.a.man.
1                                                                Yes
2                                                                Yes
  Does.a.woman.have.the.same.rights.to.remarry.as.a.man. PARENTHOOD
1                                                     No        100
2                                                     No        100
  Is.paid.leave.of.at.least.14.weeks.available.to.mothers.
1                                                      Yes
2                                                      Yes
  Length.of.paid.maternity.leave
1                            126
2                             98
  Does.the.government.administer.100.percent.of.maternity.leave.benefits.
1                                                                     Yes
2                                                                     Yes
  Is.there.paid.leave.available.to.fathers. Length.of.paid.paternity.leave
1                                       Yes                              7
2                                       Yes                              0
  Is.there.paid.parental.leave. Shared.days Days.for.the.mother
1                           Yes          42                  42
2                           Yes           0                 309
  Days.for.the.father Is.dismissal.of.pregnant.workers.prohibited.
1                   0                                          Yes
2                 365                                          Yes
  ENTREPRENEURSHIP
1               75
2               75
  Does.the.law.prohibit.discrimination.in.access.to.credit.based.on.gender.
1                                                                        No
2                                                                        No
  Can.a.woman.sign.a.contract.in.the.same.way.as.a.man.
1                                                   Yes
2                                                   Yes
  Can.a.woman.register.a.business.in.the.same.way.as.a.man.
1                                                       Yes
2                                                       Yes
  Can.a.woman.open.a.bank.account.in.the.same.way.as.a.man. ASSETS
1                                                       Yes     60
2                                                       Yes    100
  Do.women.and.men.have.equal.ownership.rights.to.immovable.property.
1                                                                  No
2                                                                 Yes
  Do.sons.and.daughters.have.equal.rights.to.inherit.assets.from.their.parents.
1                                                                           Yes
2                                                                           Yes
  Do.male.and.female.surviving.spouses.have.equal.rights.to.inherit.assets.
1                                                                       Yes
2                                                                       Yes
  Does.the.law.grant.spouses.equal.administrative.authority.over.assets.during.marriage.
1                                                                                     No
2                                                                                    Yes
  Does.the.law.provide.for.the.valuation.of.nonmonetary.contributions. PENSION
1                                                                  Yes      75
2                                                                  Yes     100
  Is.the.age.at.which.women.and.men.can.retire.with.full.pension.benefits.the.same.
1                                                                                No
2                                                                               Yes
  Is.the.age.at.which.women.and.men.can.retire.with.partial.pension.benefits.the.same.
1                                                                                  Yes
2                                                                                  Yes
  Is.the.mandatory.retirement.age.for.women.and.men.the.same.
1                                                         Yes
2                                                         Yes
  Are.periods.of.absence.due.to.childcare.accounted.for.in.pension.benefits.
1                                                                        Yes
2                                                                        Yes
  match   X Country.Code Foreign_direct_investment
1  TRUE  39          CHL                      2.68
2  TRUE 119          JPN                      0.50
  agriculture_forestry_value_added GNI.per.capita
1                             3.76          14610
2                            -6.69          41800
  net_barter_terms_of_trade_index gdp_per_person_employed
1                          111.33                64061.38
2                           97.09                85738.02
threshold_score <- 80
count_over_threshold_region <- df %>%
    group_by(Region) %>%
    filter(WBL.INDEX >= threshold_score) %>%
    count()
count_over_threshold_region
# A tibble: 6 × 2
# Groups:   Region [6]
  Region                         n
  <chr>                      <int>
1 East Asia & Pacific            7
2 Europe & Central Asia         13
3 High income: OECD             32
4 Latin America & Caribbean     17
5 Middle East & North Africa     1
6 Sub-Saharan Africa             9
threshold_score <- 80
count_over_threshold_region <- df %>%
    filter(WBL.INDEX >= threshold_score) %>%
    filter(Region == "Middle East & North Africa")
count_over_threshold_region
  Economy Economy.Code ISO.Code                     Region Income.Group
1   malta          MLT      MLT Middle East & North Africa  High income
  Report.Year WBL.INDEX MOBILITY
1        2018      88.8      100
  Can.a.woman.choose.where.to.live.in.the.same.way.as.a.man.
1                                                        Yes
  Can.a.woman.travel.outside.her.home.in.the.same.way.as.a.man.
1                                                           Yes
  Can.a.woman.apply.for.a.passport.in.the.same.way.as.a.man.
1                                                        Yes
  Can.a.woman.travel.outside.the.country.in.the.same.way.as.a.man. WORKPLACE
1                                                              Yes       100
  Can.a.woman.get.a.job.in.the.same.way.as.a.man.
1                                             Yes
  Does.the.law.prohibit.discrimination.in.employment.based.on.gender.
1                                                                 Yes
  Is.there.legislation.on.sexual.harassment.in.employment.
1                                                      Yes
  Are.there.criminal.penalties.or.civil.remedies.for.sexual.harassment.in.employment.
1                                                                                 Yes
  PAY Does.the.law.mandate.equal.remuneration.for.work.of.equal.value.
1  75                                                              Yes
  Can.a.woman.work.at.night.in.the.same.way.as.a.man.
1                                                 Yes
  Can.a.woman.work.in.a.job.deemed.dangerous.in.the.same.way.as.a.man.
1                                                                  Yes
  Can.a.woman.work.in.an.industrial.job.in.the.same.way.as.a.man. MARRIAGE
1                                                              No      100
  Is.the.law.free.of.legal.provisions.that.require.a.married.woman.to.obey.her.husband.
1                                                                                   Yes
  Can.a.woman.be.head.of.household.in.the.same.way.as.a.man.
1                                                        Yes
  Is.there.legislation.specifically.addressing.domestic.violence.
1                                                             Yes
  Can.a.woman.obtain.a.judgment.of.divorce.in.the.same.way.as.a.man.
1                                                                Yes
  Does.a.woman.have.the.same.rights.to.remarry.as.a.man. PARENTHOOD
1                                                    Yes         60
  Is.paid.leave.of.at.least.14.weeks.available.to.mothers.
1                                                      Yes
  Length.of.paid.maternity.leave
1                            126
  Does.the.government.administer.100.percent.of.maternity.leave.benefits.
1                                                                      No
  Is.there.paid.leave.available.to.fathers. Length.of.paid.paternity.leave
1                                       Yes                              1
  Is.there.paid.parental.leave. Shared.days Days.for.the.mother
1                            No           0                   0
  Days.for.the.father Is.dismissal.of.pregnant.workers.prohibited.
1                   0                                          Yes
  ENTREPRENEURSHIP
1              100
  Does.the.law.prohibit.discrimination.in.access.to.credit.based.on.gender.
1                                                                       Yes
  Can.a.woman.sign.a.contract.in.the.same.way.as.a.man.
1                                                   Yes
  Can.a.woman.register.a.business.in.the.same.way.as.a.man.
1                                                       Yes
  Can.a.woman.open.a.bank.account.in.the.same.way.as.a.man. ASSETS
1                                                       Yes    100
  Do.women.and.men.have.equal.ownership.rights.to.immovable.property.
1                                                                 Yes
  Do.sons.and.daughters.have.equal.rights.to.inherit.assets.from.their.parents.
1                                                                           Yes
  Do.male.and.female.surviving.spouses.have.equal.rights.to.inherit.assets.
1                                                                       Yes
  Does.the.law.grant.spouses.equal.administrative.authority.over.assets.during.marriage.
1                                                                                    Yes
  Does.the.law.provide.for.the.valuation.of.nonmonetary.contributions. PENSION
1                                                                  Yes      75
  Is.the.age.at.which.women.and.men.can.retire.with.full.pension.benefits.the.same.
1                                                                               Yes
  Is.the.age.at.which.women.and.men.can.retire.with.partial.pension.benefits.the.same.
1                                                                                  Yes
  Is.the.mandatory.retirement.age.for.women.and.men.the.same.
1                                                         Yes
  Are.periods.of.absence.due.to.childcare.accounted.for.in.pension.benefits.
1                                                                         No
  match   X Country.Code Foreign_direct_investment
1  TRUE 159          MLT                     29.12
  agriculture_forestry_value_added GNI.per.capita
1                             3.41          27610
  net_barter_terms_of_trade_index gdp_per_person_employed
1                           98.74                103841.5
perfect_score <- 100
count_perfect_region <- df %>%
    filter(WBL.INDEX == perfect_score)
nrow(count_perfect_region)
[1] 7
## distribution of mobility scores
# histogram
mobility_p <- ggplot(df, aes(x = MOBILITY, fill= Region)) +
    geom_histogram(binwidth = 20) +
    theme_minimal() +
    labs(
        title = "Distribution of Mobility Scores by Region",
        x = "Mobility Score",
        y = "Frequency"
    ) +
    scale_x_continuous(breaks = seq(0, 100, by = 20)) +
    theme_minimal()

ggplotly(mobility_p)
## distribution of mobility scores without region
# histogram
ggplot(df, aes(x = MOBILITY, )) +
    geom_histogram(binwidth = 20, fill = "skyblue", color = "black") +
    stat_bin(binwidth = 20, geom = "text", aes(label = ..count..), vjust = -0.5) +
    labs(
        title = "Distribution of Mobility Scores",
        x = "Mobility Score",
        y = "Count"
    ) +
    theme(plot.title = element_text(hjust = 0.5)) +
    scale_x_continuous(breaks = seq(0, 100, by = 20))

scored_indicators <- df |> select(MOBILITY, WORKPLACE, PAY, MARRIAGE, PARENTHOOD, ENTREPRENEURSHIP, ASSETS, PENSION, )

data_long <- gather(scored_indicators, key = "variable", value = "value")

# Faceted plot showing distribution for each variable
ggplot(data_long, aes(x = value)) +
    geom_histogram(binwidth = 20, fill = "skyblue", color = "black") +
    facet_wrap(~variable, scales = "free") +
    labs(title = "Distribution of Scored Indicators", x = "Value", y = "Frequency") + theme(plot.title = element_text(hjust = 0.5))

# compare mobility score across regions
ggplot(df, aes(x = Region, y = MOBILITY, fill = Region)) +
    geom_boxplot() +
    scale_x_discrete(labels = region_labels) +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
    labs(title = "Mobility Scores by Region", x = "Region", y = "Mobility Score")

# compare wbl score across regions
ggplot(df, aes(x = Region, y = WBL.INDEX, fill = Region)) +
    geom_boxplot() +
    scale_x_discrete(labels = region_labels) +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
    labs(title = "WBL Scores by Region", x = "Region", y = "WBL Score")

# select mobility-related categorical columns
mobility_categorical <- df %>%
    select(Region, Can.a.woman.choose.where.to.live.in.the.same.way.as.a.man., Can.a.woman.travel.outside.her.home.in.the.same.way.as.a.man., Can.a.woman.apply.for.a.passport.in.the.same.way.as.a.man., Can.a.woman.travel.outside.the.country.in.the.same.way.as.a.man.)

# convert long for visualization
mobility_long <- mobility_categorical %>%
    pivot_longer(cols = -Region, names_to = "Indicator", values_to = "Response")

# calculate proportions
mobility_proportions <- mobility_long %>%
    group_by(Region, Indicator, Response) %>%
    summarise(Count = n(), .groups = "drop") %>%
    mutate(Proportion = Count / sum(Count))

mobility_proportions
# A tibble: 45 × 5
   Region                Indicator                     Response Count Proportion
   <chr>                 <chr>                         <chr>    <int>      <dbl>
 1 East Asia & Pacific   Can.a.woman.apply.for.a.pass… No           6    0.00789
 2 East Asia & Pacific   Can.a.woman.apply.for.a.pass… Yes         19    0.025  
 3 East Asia & Pacific   Can.a.woman.choose.where.to.… No           3    0.00395
 4 East Asia & Pacific   Can.a.woman.choose.where.to.… Yes         22    0.0289 
 5 East Asia & Pacific   Can.a.woman.travel.outside.h… No           2    0.00263
 6 East Asia & Pacific   Can.a.woman.travel.outside.h… Yes         23    0.0303 
 7 East Asia & Pacific   Can.a.woman.travel.outside.t… Yes         25    0.0329 
 8 Europe & Central Asia Can.a.woman.apply.for.a.pass… No           1    0.00132
 9 Europe & Central Asia Can.a.woman.apply.for.a.pass… Yes         22    0.0289 
10 Europe & Central Asia Can.a.woman.choose.where.to.… Yes         23    0.0303 
# ℹ 35 more rows
# look up table for mobility indicators
mobility_labels <- c(
    "Can.a.woman.choose.where.to.live.in.the.same.way.as.a.man." = "Choice of Living Situation", "Can.a.woman.travel.outside.her.home.in.the.same.way.as.a.man." = "Travel Outside Home", "Can.a.woman.apply.for.a.passport.in.the.same.way.as.a.man." = "Passport Acquisition", "Can.a.woman.travel.outside.the.country.in.the.same.way.as.a.man." = "Intercontinental Travel"
)

# visualize proportions

ggplot(mobility_proportions, aes(x = Region, y = Proportion, fill = Response)) +
    geom_bar(stat = "identity", position = "fill") +
    facet_wrap(~Indicator, scales = "free", labeller = labeller(Indicator = mobility_labels)) +
    scale_x_discrete(labels = region_labels) +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
    labs(
        title = "Proportions of Yes/No Responses for Mobility Indicators By Region",
        x = "Region", y = "Proportion"
    )

mob_plt_1 <- ggplot(df, aes(x = Can.a.woman.choose.where.to.live.in.the.same.way.as.a.man., fill = Region)) +
    geom_bar(position = "dodge") + # 'dodge' puts bars side by side
    labs(title = "Can a woman choose where to live in the same way as a man by Region", x = "Can a woman choose where to live in the same way as a man", y = "Count") +
    theme_minimal()

ggplotly(mob_plt_1)
mob_plt_2 <- ggplot(df, aes(x = Can.a.woman.travel.outside.her.home.in.the.same.way.as.a.man., fill = Region)) +
    geom_bar(position = "dodge") + # 'dodge' puts bars side by side
    labs(title = "Can a woman travel outside her home in the same way as a man", x = "Can a woman travel outside her home in the same way as a man", y = "Count") +
    theme_minimal()

ggplotly(mob_plt_2)
mob_plt_3 <- ggplot(df, aes(x = Can.a.woman.apply.for.a.passport.in.the.same.way.as.a.man., fill = Region)) +
    geom_bar(position = "dodge") + # 'dodge' puts bars side by side
    labs(title = "Can a woman apply for a passport in the same way as a man", x = "Can a woman apply for a passport in the same was as a man", y = "Count") +
    theme_minimal()

ggplotly(mob_plt_3)
mob_plt_4 <- ggplot(df, aes(x = Can.a.woman.travel.outside.the.country.in.the.same.way.as.a.man., fill = Region)) +
    geom_bar(position = "dodge") + # 'dodge' puts bars side by side
    labs(title = "Can a woman travel outside the country in the same way as a man?", x = "Can a woman travel outside the country in the same way as a man?", y = "Count") +
    theme_minimal()

ggplotly(mob_plt_4)
# Welch Two Sample t-test
t_test_result <- t.test(MOBILITY ~ Can.a.woman.choose.where.to.live.in.the.same.way.as.a.man., data = df)

print(t_test_result)

    Welch Two Sample t-test

data:  MOBILITY by Can.a.woman.choose.where.to.live.in.the.same.way.as.a.man.
t = -11.11, df = 38.442, p-value = 1.449e-13
alternative hypothesis: true difference in means between group No and group Yes is not equal to 0
95 percent confidence interval:
 -58.07865 -40.18138
sample estimates:
 mean in group No mean in group Yes 
         46.62162          95.75163 
# Welch Two Sample t-test
t_test_result <- t.test(MOBILITY ~ Can.a.woman.travel.outside.her.home.in.the.same.way.as.a.man., data = df)

print(t_test_result)

    Welch Two Sample t-test

data:  MOBILITY by Can.a.woman.travel.outside.her.home.in.the.same.way.as.a.man.
t = -12.536, df = 17.37, p-value = 3.921e-10
alternative hypothesis: true difference in means between group No and group Yes is not equal to 0
95 percent confidence interval:
 -78.48727 -55.90579
sample estimates:
 mean in group No mean in group Yes 
         25.00000          92.19653 
# Welch Two Sample t-test
t_test_result <- t.test(MOBILITY ~ Can.a.woman.apply.for.a.passport.in.the.same.way.as.a.man., data = df)

print(t_test_result)

    Welch Two Sample t-test

data:  MOBILITY by Can.a.woman.apply.for.a.passport.in.the.same.way.as.a.man.
t = -8.5657, df = 48.039, p-value = 3.098e-11
alternative hypothesis: true difference in means between group No and group Yes is not equal to 0
95 percent confidence interval:
 -46.41090 -28.76507
sample estimates:
 mean in group No mean in group Yes 
         56.70732          94.29530 
# Welch Two Sample t-test
t_test_result <- t.test(MOBILITY ~ Can.a.woman.travel.outside.the.country.in.the.same.way.as.a.man., data = df)

print(t_test_result)

    Welch Two Sample t-test

data:  MOBILITY by Can.a.woman.travel.outside.the.country.in.the.same.way.as.a.man.
t = -18.855, df = 10.716, p-value = 1.46e-09
alternative hypothesis: true difference in means between group No and group Yes is not equal to 0
95 percent confidence interval:
 -89.83431 -70.99902
sample estimates:
 mean in group No mean in group Yes 
         10.00000          90.41667 
# scatter plot for Mobility score vs gpd per person employed
reg_mob <- ggplot(df, aes(x = MOBILITY, y = gdp_per_person_employed)) +
    geom_point() +
    geom_smooth(method = "lm", color = "red") +
    theme_minimal() +
    labs(
        title = "Mobility Score vs GDP per Person Employed",
        x = "Mobility Score", y = "GDP per Person Employed"
    )
ggplotly(reg_mob)
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 1 row containing non-finite outside the scale range
(`stat_smooth()`).
# density plot
ggplot(df, aes(x = MOBILITY)) +
    geom_density(fill = "skyblue", alpha = 0.5, color = "black") +
    geom_vline(aes(xintercept = mean(MOBILITY, na.rm = TRUE)), color = "red", linetype = "dashed", linewidth = 1) +
    geom_vline(aes(xintercept = median(MOBILITY, na.rm = TRUE)), color = "blue", linetype = "dashed", linewidth = 1) +
    theme_minimal() +
    labs(title = "Density of Mobility Score", x = "Mobility Score", y = "Density") +
    annotate("text", x = mean(df$MOBILITY, na.rm = TRUE), y = 0.015, label = "Mean", color = "red", angle = 90, vjust = 1.5) +
    annotate("text", x = median(df$MOBILITY, na.rm = TRUE), y = 0.012, label = "Median", color = "blue", angle = 90, vjust = 1.5)

print(mean(df$MOBILITY))
[1] 86.18421
print(median(df$MOBILITY))
[1] 100